util, sse2-float: make sure 1 maps to 1 in linear -> gamma conversions
authorEll <ell_se@yahoo.com>
Thu, 11 Jan 2018 14:19:50 +0000 (09:19 -0500)
committerEll <ell_se@yahoo.com>
Thu, 11 Jan 2018 14:26:03 +0000 (09:26 -0500)
Add a small offset to the result of the linear -> gamma
conversions, such that an input value of 1.0 maps to an output
value of 1.0, exactly.

babl/base/util.h
extensions/sse2-float.c

index e273087540725f14883929595cebb4dfe739a0db..50bba74b170eeb7192ab75879ea630fd1774f101 100644 (file)
@@ -81,7 +81,12 @@ static inline float
 babl_linear_to_gamma_2_2f (float value)
 {
   if (value > 0.003130804954f)
-    return 1.055f * babl_pow_1_24f (value) - 0.055f;
+    {
+      return 1.055f * babl_pow_1_24f (value) -
+             (0.055f                         -
+              3.0f / (float) (1 << 24));
+              /* ^ offset the result such that 1 maps to 1 */
+    }
   return 12.92f * value;
 }
 
index 223f85ce085fbeb17417c65f4f68839eca75ed1f..41a00b2d587314432d1cf1c7329e4c04a9c22755 100644 (file)
@@ -304,7 +304,10 @@ sse_pow_24 (__v4sf x)
 static inline __v4sf
 linear_to_gamma_2_2_sse2 (__v4sf x)
 {
-  __v4sf curve = sse_pow_1_24 (x) * splat4f (1.055f) - splat4f (0.055f);
+  __v4sf curve = sse_pow_1_24 (x) * splat4f (1.055f) -
+                 splat4f (0.055f                     -
+                          3.0f / (float) (1 << 24));
+                          /* ^ offset the result such that 1 maps to 1 */
   __v4sf line = x * splat4f (12.92f);
   __v4sf mask = _mm_cmpgt_ps (x, splat4f (0.003130804954f));
   return _mm_or_ps (_mm_and_ps (mask, curve), _mm_andnot_ps (mask, line));